package com.promis.fastdfs;

import com.promis.util.CollectionUtils;
import com.promis.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class FastStoreHelper {
	
    public static List<FastStore> getFastStoreListByFullPaths(String[] fullPaths) {
    	List<FastStore> FastStoreList = new ArrayList<FastStore>();
    	if (!CollectionUtils.isNullOrEmpty(fullPaths)) {
			for (String fullPath : fullPaths) {
				FastStore newImgScene = getFastStoreByFullPath(fullPath);
				FastStoreList.add(newImgScene);
			}
    	}
		return FastStoreList;
    }
    
	public static String getFullPathByFastStore(FastStore FastStore) {
		return getFullPathByGroupPath(FastStore.getGroup(), FastStore.getPath());
	}
	
	public static String getFullPathByGroupPath(String group, String path) {
		if (StringUtils.isNullOrEmpty(group) || StringUtils.isNullOrEmpty(path)) return null;
		return "/" + group + "/" + path;
	}
	
	public static FastStore getFastStoreByFullPath(String fullPath) {
        if (StringUtils.isNullOrEmpty(fullPath)) return null;
        
        String fp = fullPath.substring(1, fullPath.length());
        String group = fp.substring(0, fp.indexOf("/"));
        String path = fp.substring(fp.indexOf("/") + 1, fp.length());

        return getFastStoreByGroupPath(group, path);
    }
	
	private static FastStore getFastStoreByGroupPath(String group, String path) {
		if (StringUtils.isNullOrEmpty(group) || StringUtils.isNullOrEmpty(path)) return null;
		FastStore FastStore = new FastStore();
		FastStore.setGroup(group);
		FastStore.setPath(path);
		return FastStore;
	}
}
